<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head th:include="include :: header"></head>
<style>
html{background:#fff;}
body{padding:0 0 5px 0!important;}
body>form>ul{background:#fff;}
</style>
<link rel="stylesheet"    th:href="@{/lib/ztree/css/zTreeStyle/zTreeStyle.css}" type="text/css" media="all">
<body>
<form class="layui-form layui-form-pane" action="" id="saveForm">
    <ul id="ztree" class="ztree"></ul>
    <input type="hidden" id="parentId" name="parentId" th:value="${dept.parentId}"/>
    <input type="hidden" id="deptId" name="deptId" th:value="${dept.deptId}"/>
    <input type="hidden"  id="parentIdOld" name="parentIdOld" th:value="${dept.parentId}" />
   <div class="layui-form-item" style="display:none;">
    <button class="layui-btn" lay-submit="" lay-filter="saveSubmit">提交</button>
  </div>
</form>

  <div th:include="include :: footer"></div>
<script type="text/javascript" th:src="@{/lib/ztree/js/jquery.ztree.core.js}"></script>
	<script type="text/javascript" th:src="@{/lib/ztree/js/jquery.ztree.excheck.js}"></script>
	<script type="text/javascript" th:src="@{/lib/ztree/js/jquery.ztree.exedit.js}"></script>
	<script>

	layui.config({
		base :  cxt+'layuiadmin/' //静态资源所在路径
	}).extend({
		webplus : 'lib/webplus' //主入口模块
	}).use([ 'table', 'form','webplus' ], function() {
		var $ = layui.$, 
		form = layui.form, 
		webplus=layui.webplus;
		var setting = {
			check: {
				enable: false
			},
			data: {
				simpleData: {
					enable: true
				}
			},
			callback: {
				onClick: zTreeOnClick//节点点击事件
			}
		};
		function zTreeOnClick(event, treeId, treeNode) {
			//获取当前树节点
			var treeObj = $.fn.zTree.getZTreeObj("ztree");
			var id=treeNode.id;
			var deptId=$("#deptId").val();
			var parentIdOld=$("#parentIdOld").val();
			var parentNode = treeObj.getNodeByParam("id", parentIdOld);//根据ID找到该节点
			var deptNode = treeObj.getNodeByParam("id", deptId);//根据ID找到该节点
			if(deptId==id){
				//恢复回原来的上级机构
				treeObj.selectNode(parentNode);//根据该节点选中
				$("#parentId").val(parentIdOld);
				webplus.alertWarn('机构移动不允许移动到当前机构【'+deptNode.name+'】，系统将恢复原来的上级机构');
				return  false;
			}
			var  nodes =treeObj.transformToArray(deptNode); 
			for(var i=0; i<nodes.length; i++){
				var nodeId=nodes[i].id;
				if(id==nodeId){
					//恢复回原来的上级机构
					treeObj.selectNode(parentNode);//根据该节点选中
					 $("#parentId").val(parentIdOld);
					 webplus.alertWarn('机构移动不允许移动到当前机构【'+deptNode.name+'】下面的机构，其中你选择的机构【'+nodes[i].name+'】，系统将恢复原来的上级机构', 'warning');
					return ;
				}
			}
			 $("#parentId").val(id);
		};
		var selectId=$("#parentId").val();
		webplus.initTree("system/dept/loadDeptTree",setting,'','',selectId)
		webplus.initForm('system/dept/saveMoveDept');
	});
	</script>

<link rel="stylesheet"    th:href="@{/css/common/openshow.css}" media="all"/>

</body>
</html>